// const userM = require('./user_m/routes/index') // 用户注册登录相关模块
// const articleM = require('./article_m/routes/index') // 文章相关模块
import Router from 'koa-router'
const router = new Router()
import fs from 'fs'
import path from 'path'

/// 自动注册以_m结尾的每个模块下文件夹名为routes的路由
const prefix = '/api' /// 统一添加api前缀
const files = fs.readdirSync(__dirname)
files
	.filter(file => file.endsWith('_m'))
	.forEach( file => {
		const  file_entity =   require(path.join(__dirname, `${file}/routes/index`))
		router.use(prefix, file_entity.default.routes(), file_entity.default.allowedMethods())
	})

export default router